package com.erp.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.erp.common.R;
import com.erp.entity.Cash;
import com.erp.service.CashService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@Slf4j
@RestController
@RequestMapping("/cash")
@RequiresRoles(value = {"FinancialAdministrator","SupperAdministrator"},logical = Logical.OR)
public class CashController {

    @Autowired
    private CashService cashService;

    @PostMapping
    public R<String> save(@RequestBody Cash cash) {
        cash.setCreateDateTime(LocalDateTime.now());
        return cashService.saveCashAndLedger(cash);
    }

    @GetMapping("/page")
    public R<Page<Cash>> page(int page , int pageSize){
        Page<Cash> cashPage = new Page<>(page,pageSize);
        return R.success(cashService.page(cashPage));
    }
}
